﻿@using MvcContrib.UI.Grid
@using XRM.Security.WebUI.MvcHelpers
@using XRM.Security.WebUI.Security
@model List<XRM.Security.WebUI.Models.SystemUser.SystemUserModel>
@{
    ViewBag.Title = "Сотрудники";
    ViewBag.HideHeader = true;
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section scripts
{
    @Scripts.Render("~/bundles/gridlibrary")
}

<div>
    <p>
        @Html.DialogFormButton(new DialogButtonOptions()
           {
               Text = "Добавить пользователя",
               ContentUrl = Url.Action("ADUsersDialog"),
               Id = "dlgADUsersDialog",
               ButtonCss = "btn btn-large btn-primary",
               OnOpen = "SetFocusDialog",
               OnSuccess = "GotoEdit"
           })
    </p>
    
    @{
        if(Model.Any())
        {
            Html.Grid(Model).Columns(column =>
            {
                column.For(item => Html.ActionLink(item.LastName, "Edit", "SystemUser", new { id = item.Id }, null)).Named("Фамилия");
                column.For(item => item.FirstName).Named("Имя");
                column.For(item => item.MotherName).Named("Отчество");
                column.For(item => item.Post).Named("Должность");
                column.For(item => item.Login).Named("Пользователь домена");
                column.Custom(@<text>@Html.Raw(item.RolesColumnData)</text>).Named("Назначенные роли");
                column.Custom(@<text>
                                @if ( item.Id != UserPrincipal.Current.UserId )
                                {
                                    @Html.Partial( "_GridActionsPartial", new ViewDataDictionary { { "Controller", "SystemUser" }, { "Id", item.Id } } )
                                }
                              </text>)
                      .Named( "<i class='fa fa-trash-o fa-action'></i>" )
                      .Attributes( @class => "single-action" );
            }).Attributes(@class => "table table-striped table-bordered", id => "table_id")
              .Render();
        }
    }
</div>

<script type="text/javascript">
    $(document).ready(function () {
        @if (Model.Any())
        {
            <text>
            $('#table_id').dataTable({
                "aoColumnDefs": [{ 'bSortable': false, 'aTargets': [5] }, { 'bSortable': false, 'aTargets': [6] }],
                paging: false,
                bFilter: false,
                info: false,
                "order": [[0, "asc"]]
            });
            </text>
        }
        
    });
    function SetFocusDialog() {
        setFocus($('#SearchString'));
    }
    function GotoEdit() {
        window.location = '@(Url.Action("Edit"))';
    }
</script>